using System;
using System.Collections;
using System.Web;
using Sedna.Core.Controller;
using Sedna.Core.Controller.Common;

namespace Sedna.Core.Controls.Actions
{
	/// <summary>
	/// Summary description for CopyContextValuesAction.
	/// </summary>
	public class CopyContextValuesAction : AbstractAction
	{
		private IDictionary keyCopyFrom = new Hashtable();
        private IDictionary keyCopyTo = new Hashtable();

        # region Properties

        /// <summary>
        /// Dictionary for copy ExecutionContext elements value
		/// 
		/// key - path copy from
		/// value - path copty to
		/// 
		/// </summary>
        public IDictionary KeyCopyFrom
		{
            set { keyCopyFrom = value; }
        }

        /// <summary>
        /// Dictionary for copy ExecutionContext elements value
        /// 
        /// key - path copy to
        /// value - path copy from
        /// 
        /// </summary>
        public IDictionary KeyCopyTo
	    {
            set { keyCopyTo = value; }
	    }

	    # endregion

        public override IActionResult Execute(IExecutionContext executionContext)
		{
            foreach (String key in keyCopyFrom.Keys)
			{
                executionContext.SetPropertyValue(keyCopyFrom[key].ToString(), executionContext.GetPropertyValue(key));
			}

            foreach (String key in keyCopyTo.Keys)
            {
                executionContext.SetPropertyValue(key, executionContext.GetPropertyValue(keyCopyTo[key].ToString()));                
            }
            
			return CreateResult(successStatus);
		}
	}
}
